package com.cxd.base.util.wtj;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;


/**
 * @author wtj
 * @date 2015年12月1日 下午4:16:20
 * @company CXD
 * @version [Copyright (c) 2015 V001]
 */
public class FUtils {
	
	/**
	 * form 表单转实体 bean 
	 */
	public static <T> T formToBean(Class<T> clazz,HttpServletRequest request)throws InstantiationException,IllegalAccessException {
		T bean = (T) clazz.newInstance();
		Field[] fields = clazz.getClass().getDeclaredFields();
		for (int i = 0; i < fields.length; i++) {
			String fieldName = fields[i].getName();
			String fieldValue = request.getParameter(fieldName);
			if(fieldValue==null || fieldValue==""){
				continue;
			}
			fields[i].setAccessible(true);
			BUtils.setBean(bean,fields[i],fieldValue);
		}
		return bean;
	}
}
